package com.cljz.makepassenger.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.cljz.makepassenger.R;
import com.cljz.makepassenger.ui.holder.InvitationShareHolder;

/**
 * Created by apple on 2017/4/10.
 */

public class InvitationShareAdapter extends RecyclerView.Adapter<InvitationShareHolder> {
    private Context context;
    private int[] shareIcon;
    private OnItemClickListener mOnItemClickListener;

    public InvitationShareAdapter(Context context, int[] shareIcon) {
        this.context = context;
        this.shareIcon = shareIcon;
    }

    @Override
    public InvitationShareHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new InvitationShareHolder(View.inflate(context, R.layout.item_share,null));
    }

    @Override
    public void onBindViewHolder(InvitationShareHolder holder, final int position) {
        holder.setData(shareIcon, position);
        if (mOnItemClickListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mOnItemClickListener.onClick(position);
                }
            });
            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    mOnItemClickListener.onLongClick(position);
                    return false;
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return shareIcon == null ? 0 : shareIcon.length;
    }

    public interface OnItemClickListener {
        void onClick(int position);

        void onLongClick(int position);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }
}
